package com.bysj.yqsht.service.impl;

import com.bysj.yqsht.bean.Activity;
import com.bysj.yqsht.bean.ActivityExample;
import com.bysj.yqsht.bean.extend.ActivityExtend;
import com.bysj.yqsht.dao.ActivityMapper;
import com.bysj.yqsht.dao.extend.ActivityExtendMapper;
import com.bysj.yqsht.service.IActivityService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IActivityServiceImpl implements IActivityService {
    @Resource
    private ActivityMapper activityMapper;
  @Resource
    private ActivityExtendMapper activityExtendMapper;

    @Override
    public List<Activity> findAll() {
        ActivityExample example  =new ActivityExample();
        return activityMapper.selectByExample(example);
    }

    @Override
    public List<ActivityExtend> findWithAll(int pageNum, int limit) {
        PageHelper.startPage(pageNum,limit);
        ActivityExample example = new ActivityExample();
        List<ActivityExtend> list1 = activityExtendMapper.findWithAll();
        PageInfo<ActivityExtend> data = new PageInfo<ActivityExtend>(list1);
        List<ActivityExtend> list = data.getList();
        return list;

    }

    @Override
    public List<ActivityExtend> findWithAllBy(String name, String classId) {
        return activityExtendMapper.findWithAllBy(name,classId);
    }

    @Override
    public void deleteById(long id) {
        activityMapper.deleteByPrimaryKey(id);

    }

    @Override
    public void saveOrUpdate(Activity activity) {
        if(activity.getId() != null){
            activityMapper.updateByPrimaryKey(activity);
        } else {
            activityMapper.insert(activity);
        }

    }
}
